import { createSlice, PayloadAction } from '@reduxjs/toolkit';

interface DetectionRecord {
  timestamp: string;
  angle: number;
  distance: number;
  email?: string;
}

interface DetectionState {
  history: DetectionRecord[];
}

const initialState: DetectionState = {
  history: []
};

const detectionSlice = createSlice({
  name: 'detection',
  initialState,
  reducers: {
    addRecord: (state, action: PayloadAction<DetectionRecord>) => {
      state.history.unshift(action.payload);
    },
    clearHistory: (state) => {
      state.history = [];
    }
  }
});

export const { addRecord, clearHistory } = detectionSlice.actions;
export default detectionSlice.reducer; 